package lib.bone.flow.domain.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.hibernate.Hibernate;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;
import java.util.Objects;

/**
 * @author: kindear
 * 流程任务分配
 */
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
@Table(name = "flow_task_assign")
@EntityListeners(AuditingEntityListener.class)
@GenericGenerator(name = "jpa-uuid", strategy = "uuid")
public class FlowTaskAssign {
    @Id
    @GeneratedValue(generator = "jpa-uuid")
    @ApiModelProperty(value = "分配记录ID",name = "id")
    String id;

    /**
     * 流程定义编码
     */
    @ApiModelProperty("流程定义编码")
    @Column(name = "flow_define_code")
    String flowDefineCode;

    /**
     * 对应流程节点ID
     */
    @ApiModelProperty("流程节点ID")
    @Column(name = "flow_node_id")
    String flowNodeId;

    /**
     * 指派对象
     */
    @ApiModelProperty(value = "指派对象",notes = "DEPT / ROLE / USER")
    @Column(name = "assign_type")
    String assignType;

    /**
     * 指派对象ID
     */
    @ApiModelProperty("指派对象ID")
    @Column(name = "assign_id")
    String assignId;

    /**
     * 对于学院预审核
     */
    @ApiModelProperty(value = "是否是二级院预审人员",notes = "1 为二级院预审人员 0 则不是")
    @Column(name = "is_college")
    Integer isCollege;

    @ApiModelProperty(value = "二级院ID",notes = "预审人员负责的2级院ID")
    @Column(name = "dept_id")
    Long deptId;

    @CreatedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录创建时间",name = "createdTime")
    @Column(name = "created_time")
    private Date createdTime;
    @LastModifiedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录更新时间",name = "updatedTime")
    @Column(name = "updated_time")
    private Date updatedTime;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
        FlowTaskAssign that = (FlowTaskAssign) o;
        return id != null && Objects.equals(id, that.id);
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }
}
